package com.demo.oauth.controller;

import java.util.ArrayList;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.task.TaskExecutor;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.oauth2.provider.endpoint.TokenEndpoint;
import org.springframework.security.oauth2.provider.token.ConsumerTokenServices;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.demo.commons.domain.OauthToken;
import com.demo.commons.results.CommonEnum;
import com.demo.commons.results.CommonResult;
import com.demo.commons.results.Results;

import io.micrometer.core.instrument.util.JsonUtils;

/**
* @author yangjian
* @version 创建时间：2022年2月14日 下午5:24:13
* 
*/
@RestController
public class OauthController {
	
	@Autowired
	private TokenEndpoint endpoint;
	
	@Autowired
	private ConsumerTokenServices tokenServices;
	
	@Autowired
	private TaskExecutor executor;
	
	/**
	 * 退出时删除令牌
	 * @param accountToken
	 * @return
	 */
	@PostMapping("oauth/remove/token")
	public CommonResult<?> logout(@RequestParam String loginToken) {
		executor.execute(()->{
			tokenServices.revokeToken(loginToken);
		});
		return Results.build(CommonEnum.SUCCESS.getCode(), "退出登录成功");
	}

}
